/*
 * Copyright (c) 2014 Hai Bison
 *
 * See the file LICENSE at the root directory of this project for copying
 * permission.
 */

package haibison.simpleprovider.simplesettings;

import static haibison.simpleprovider.simplesettings.SimpleSettingsContract.TABLE_NAME;
import haibison.simpleprovider.SimpleProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;

/**
 * Simple settings provider. All calls to these methods are synchronized:
 * <p/>
 * <ul>
 * <li>{@link #insert(Uri, ContentValues)}</li>
 * <li>{@link #query(Uri, String[], String, String[], String)}</li>
 * <li>{@link #update(Uri, ContentValues, String, String[])}</li>
 * <li>{@link #delete(Uri, String, String[])}</li>
 * </ul>
 * 
 * @author Hai Bison
 *
 */
public class SimpleSettingsProvider extends SimpleProvider {

    @Override
    public boolean onCreate() {
        registerContract(SimpleSettingsContract.getAuthority(getContext()),
                TABLE_NAME, null);

        return super.onCreate();
    }// onCreate()

    @Override
    protected SQLiteOpenHelper newDbHelper() {
        return new SimpleSettingsHelper(getContext());
    }// newDbHelper()

    @Override
    public synchronized Uri insert(Uri uri, ContentValues values) {
        /*
         * Make sure to mark this method as "synchronized".
         */
        return super.insert(uri, values);
    }// insert()

    @Override
    public synchronized Cursor query(Uri uri, String[] projection,
            String selection, String[] selectionArgs, String sortOrder) {
        /*
         * Make sure to mark this method as "synchronized".
         */
        return super
                .query(uri, projection, selection, selectionArgs, sortOrder);
    }// query()

    @Override
    public synchronized int update(Uri uri, ContentValues values,
            String selection, String[] selectionArgs) {
        /*
         * Make sure to mark this method as "synchronized".
         */
        return super.update(uri, values, selection, selectionArgs);
    }// update()

    @Override
    public synchronized int delete(Uri uri, String selection,
            String[] selectionArgs) {
        /*
         * Make sure to mark this method as "synchronized".
         */
        return super.delete(uri, selection, selectionArgs);
    }// delete()

}
